#pragma once
#include "hashpackage.h"

template <class K, class V, class Hash = HashFunc<K>>
class unordmap
{
	struct SetOfV
	{
		const K& operator()(const std::pair<K, V>& kv)
		{
			return kv.first;
		}
	};
public:
	
	typedef typename HashBucket<K, std::pair<const K, V>, SetOfV, Hash>::iterator iterator;
	iterator begin()
	{
		return _ht.begin();
	}

	iterator end()
	{
		return _ht.end();
	}

	std::pair<iterator, bool> insert(const std::pair<K, V>& kv)
	{
		return _ht.insert(kv);
	}

	V& operator[](const K& key)
	{
		std::pair<iterator, bool> ret = _ht.insert(std::make_pair(key, V()));
		return ret.first->second;
	}

	const V& operator[](const K& key) const
	{
		std::pair<iterator, bool> ret = _ht.insert(std::make_pair(key, V()));
		return ret.first->second;
	}

	iterator find(const K& key)
	{
		return _ht.find(key);
	}

	bool erase(const K& key)
	{
		return _ht.erase(key);
	}

private:
	HashBucket<K, std::pair<const K, V>, SetOfV, Hash> _ht;
};